import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

/**
 * FactoryPattern
 */
public class FactoryPattern {
    public static void main(String[] args) {
        Logger.getGlobal().info(Result.valueOf(200).msg);
        Logger.getGlobal().info(Result.valueOf(404).msg);
    }
}

class Result {
    int code;
    String msg;

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    static Map<Integer, Result> cache = new HashMap<>() {
        {
            put(200, new Result(200, "OK"));
            put(302, new Result(302, "Found"));
            put(400, new Result(302, "Bad Request"));
            put(404, new Result(302, "Not Found"));
            // ...
        }
    };

    static Result valueOf(Integer statusCode) {
        assert (cache.get(statusCode)) != null;
        return cache.get(statusCode);
    }
}